<template>
  <div className="container">
      <Edit :mindMapData1="mindMapData" :mindData1="mindData"></Edit>
  </div>
</template>
<script>
import Toolbar from './components/Toolbar'
import Edit from './components/Edit'
import {mapState, mapActions, mapMutations} from 'vuex'
import {getData, getLocalConfig} from '@/components/SimpleMindMap/api'

export default {
  name: 'Index',
  props: {
    /* 编辑器的内容 */
    value: {
      type: String,
      default: "",
    },
    /* 只读 */
    readOnly: {
      type: Boolean,
      default: true,
    },
    mindData: {
      type: Object,
    },
  },
  components: {
    Edit
  },
  data() {
    return {
      // 作弊码：从localStorage中获取是否处于开发模式，值为true或false
      isInDevMode: localStorage.getItem("isInDevMode") === "true",
      show: false,
      "mindMapData": {
        "root": {
          "data": {
            "text": "计费根节点",
            "expand": true,
            "isActive": false
          },
          "children": []
        },
        "theme": {
          "template": "classic4",
          "config": {}
        },
        "layout": "logicalStructure",
        "config": {},
        "view": {
          "transform": {
            "scaleX": 1,
            "scaleY": 1,
            "shear": 0,
            "rotate": 0,
            "translateX": -300,
            "translateY": -100,
            "originX": 0,
            "originY": 0,
            "a": 1,
            "b": 0,
            "c": 0,
            "d": 1,
            "e": -300,
            "f": -100
          },
          "state": {
            "scale": 1,
            "x": -300,
            "y": -100,
            "sx": 0,
            "sy": 0
          }
        }
      }
    }
  },
  computed: {
    isZenMode() {
      return this.$store.state.SimpleMindMap.localConfig.isZenMode
    }
  },
  async created() {
    await this.initLocalConfig()
    const loading = this.$loading({
      lock: true,
      text: '正在加载，请稍后...'
    })
    loading.close()
    //console.log(this.mindMapData)
  },
  beforeDestroy() {
    var data = localStorage.getItem('SIMPLE_MIND_MAP_DATA')
    this.$emit("input", data)
    localStorage.setItem('SIMPLE_MIND_MAP_DATA', getData())
  },
  methods: {
    save() {
      console.log(this.mindMapData)
    },
    //...mapActions(['getUserMindMapData']),
    setLocalConfig(payLoad) {
      this.$store.commit('setLocalConfig', payLoad)
    },

    /**
     * @Author: 王林25
     * @Date: 2022-11-14 19:07:03
     * @Desc: 初始化本地配置
     */
    initLocalConfig() {
      let config = getLocalConfig()
      if (config) {
        this.setLocalConfig({
          ...this.$store.state.localConfig,
          ...config
        })
      }
    },
  },
}
</script>

<style lang="less" scoped>
.container {
}
</style>
